package com.hqyj.module.StaffManage.dao;

import com.github.pagehelper.PageInfo;
import com.hqyj.module.StaffManage.entity.Dept;
import com.hqyj.module.StaffManage.entity.MyPage;
import com.hqyj.module.StaffManage.entity.Staff;
import com.hqyj.module.clock.pojo.SearchBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author ：Cwd
 * @Description：StaffManage
 * @date ：2021/10/8 16:52
 */
@Component
public interface StaffManageDao {

    @Insert("INSERT into user_info(user_name,user_pwd,tel,email) " +
            "VALUES(#{userName},#{userPwd},#{tel},#{email})")
    Integer insertStaff(Staff staff);

    @Update("update user_info set user_name=#{userName}, user_pwd=#{userPwd}," +
            "tel=#{tel},email=#{email},dept_id=#{deptId},dept_name=#{deptName}," +
            "role=#{role},leave_num=#{leaveNum},lateandearly_num=#{lateandearlyNum}" +
            " where user_id=#{userId}")
    Integer updateStaff(Staff staff);

    @Select("<script>"
            + "select * from user_info "
            + "<where> "
            + "<if test='keyword != \"\" and keyword != null'>"
            + " and (dept_name like '%${keyword}%' or "
            + " leave_num like '%${keyword}%' or "
            + " lateandearly_num like '%${keyword}%' or "
            + " user_name like '%${keyword}%') "
            + "</if>"
            + "</where>"
            + "<choose>"
            + "<when test='orderBy != \"\" and orderBy != null'>"
            + " order by ${orderBy} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " order by user_id asc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Staff> list(SearchBean searchBean);

    @Insert("INSERT into dept_info (dept_id,dept_name) VALUES(#{deptId},#{deptName})")
    Integer insertDate(Dept dept);

    @Update("update dept_info set dept_id=#{deptId},dept_name=#{deptName} where id=#{id}")
    Integer updateDept(Dept dept);

    @Select("<script>"
            + "select * from dept_info "
            + "<where> "
            + "<if test='keyword != \"\" and keyword != null'>"
            + " dept_name like '%${keyword}%' "
            + "</if>"
            + "</where>"
            + "<choose>"
            + "<when test='orderBy != \"\" and orderBy != null'>"
            + " order by ${orderBy} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " order by dept_id asc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Dept> listDept(SearchBean searchBean);
}
